/*  doitTreeUI 사용법
	
	: 포함해야 할 JS -> doitTreeUI.js와 함께 import 해준다.
	<script type="text/javascript" src="<c:out value="${gsSystemDiv}"/>/tims/doitTreeUI.js"></script>
	<script type="text/javascript" src="<c:out value="${gsSystemDiv}"/>/tims/dragdrop.js"></script>
	
	1) 객체를 생성한다.
	 - 파라미터 :  tree 객체생성명 : 'treeUI'
	   	                 이미지경로 : '<c:out value="${gsSystemDiv}"/>'
	   	                 이벤트 : 이벤트 입력 방법 참조
	   	                 최대허용레벨 : default : 3
	   	                 최상위부모액션사용여부 : (사용값 : Y[사용], N[사용하지않음]) * N일 경우 액션처리 아이콘이 나타나지 않음.
	2) 데이터 입력 
	 - 상위데이터입력
	 	: treeUI.insert('0', '실험분류', '', '0', '1', 'N');
	 - 파라미터 : 일련번호 : '<c:out value="${list.expAssortSeq}" />'
	 			이름(타이틀) : '<c:out value="${list.expAssortName}" />'
	 			부모일련번호 : '<c:out value="${list.upExpAssortSeq}" />'
	 			레벨 : '<c:out value="${list.expAssortLevel}" />'
	 			순번 : '<c:out value="${list.expAssortOrd}" />'
	3) 데이터 순서정렬작업 : treeUI.generatorData();
	
	기타 ) 이벤트 입력 방법
	
	: 이벤트 입력 객체는 doitTreeUI에 포함되어 있음
	  insert, update, delete, move 최대 4가지 이벤트로 구성되어 있고 
	    필요없는 이벤트의 경우 기입하지 않음
	: useYn = 사용여부  
	: image = 이미지경로  
	: event = 실행될 이벤트  
	
	- EXAMPLE - 
	
	actionEvents.insert = {useYn : "Y", image : "/images/adm/common/button/bts_plus.gif", 	event : PopExecutor.doExpAssortInsertFrm}
	actionEvents.update = {useYn : "Y", image : "/images/adm/common/button/bts_adjust.gif", event : PopExecutor.doExpAssortUpdateFrm}
	actionEvents.del 	= {useYn : "Y", image : "/images/adm/common/button/bts_del.gif", 	event : DwrExecutor.doExpAssortDelete}
	actionEvents.move 	= {useYn : "Y", image : "/images/adm/common/button/bts_change.gif", event : DwrExecutor.doExpAssortMove}
	
	- EXAMPLE - 
	
	actionEvents.insert = {useYn : "Y", image : "/images/adm/common/button/bts_plus.gif", 	event : PopExecutor.doExpAssortInsertFrm}
	actionEvents.update = {useYn : "Y", image : "/images/adm/common/button/bts_adjust.gif", event : PopExecutor.doExpAssortUpdateFrm}
	actionEvents.del 	= {useYn : "Y", image : "/images/adm/common/button/bts_del.gif", 	event : DwrExecutor.doExpAssortDelete}
	actionEvents.move 	= {useYn : "Y", image : "/images/adm/common/button/bts_change.gif", event : DwrExecutor.doExpAssortMove}

	var treeUI = new tree('treeUI', '<c:out value="${gsSystemDiv}"/>', actionEvents, 3);

	treeUI.insert('0', '실험분류', '', '0', '1');

	<c:forEach var="list" items="${output}" varStatus="status">
		treeUI.insert('<c:out value="${list.expAssortSeq}" />',
					'<c:out value="${list.expAssortName}" />',
					'<c:out value="${list.upExpAssortSeq}" />',
					'<c:out value="${list.expAssortLevel}" />',
					'<c:out value="${list.expAssortOrd}" />');
	</c:forEach>

	treeUI.generatorData();
*/

// Tooltip을 위한 layer 생성
document.write('<div id="docTipsLayer" style="position: absolute; z-index: 10000; visibility: hidden; left: 0px; top: 0px; width: 10px">&nbsp;</div>');

var docTips;
var tree = Class.create();
var	actionEvents =  { "insert" 	: { useYn : 'N', 	image : null, 	event : null, title : "등록", limit : -1},
					  "update" 	: { useYn : 'N', 	image : null, 	event : null, title : "수정", limit : -1},
					  "del"		: { useYn : 'N', 	image : null, 	event : null, title : "삭제", limit : -1},
					  "select"	: { useYn : 'N', 	image : null, 	event : null, title : "선택", limit : 1},
					  "move2"	: { useYn : 'N', 	image : null, 	event : null, title : "노드이동", limit : -1},
					  "move"   	: { useYn : 'N', 	image : null, 	event : null, title : "순서변경", limit : -1},
					  "manage"	: { useYn : 'N', 	image : null, 	event : null, title : "관리", limit : -1},
					  "etc" : []
					}
var changeData = false;		
tree.prototype = {
	objectName : null,
	imagePath : null,
	buffer : new Array(),
	mapData : new JMap(),
	actionElement : null,
	action : null,
	actionEvents : null,
	allowLevel : 3,
	masterActionYn : "Y",
	enableActionEventCount : 0,
	selectedData : new JMap(),
	ect : null,
	
	initialize : function(objectName, imagePath, event, allowLevel, masterActionYn){
		this.objectName = objectName;
		this.imagePath = imagePath;
		this.actionEvents = event;
		this.allowLevel = allowLevel;
		if (this.actionEvents.insert.title == null)
			this.actionEvents.insert.title = "등록";
		if (this.actionEvents.update.title == null)
			this.actionEvents.update.title = "수정";
		if (this.actionEvents.del.title == null)
			this.actionEvents.del.title = "삭제";
		if (this.actionEvents.select.title == null)
			this.actionEvents.select.title = "선택";
		if (this.actionEvents.move2.title == null)
			this.actionEvents.move2.title = "노드이동";
		if (this.actionEvents.move.title == null)
			this.actionEvents.move.title = "순서변경";
		if (this.actionEvents.manage.title == null)
			this.actionEvents.manage.title = "관리";
			
		if(this.actionEvents.etc.length > 0) {
			this.etc = this.actionEvents.etc;
		}	
		
		this.initializeTooltip();
		if (masterActionYn != null && masterActionYn != undefined)
			this.masterActionYn = masterActionYn;
	},
	
	initializeTooltip : function() {
		
		docTips = new TipObj('docTips');
		with (docTips)
		{
		  template = '<table cellpadding="1" cellspacing="0" width="%2%" border="0">' +
		  '<tr><td><table bgcolor="white" cellpadding="3" cellspacing="0" width="100%" border="1">' +
		  '<tr><td class="tipClass">%3%</td></tr></table></td></tr></table>';
		}
	},
		
	createEntity : function(seq, title, parentSeq, level, order, extend) {
		var temp = {
			seq : seq,
			title : title,
			parentSeq : parentSeq,
			level : level,
			order : order,
			extend : extend || {},
			child : null
		}
		
		return temp;		
	},

	insert : function (seq, title, parentSeq, level, order, extend) {
		this.mapData.put(seq, this.createEntity( seq, title, parentSeq, level, order, extend));
	},
	
	generatorData : function() {
		var temp = new Array();
		if (this.mapData.size() == 0 )
			return;
		var mapKeys = this.mapData.keys();
		var mapLength = mapKeys.length;
		for(var i = 0 ; i < mapLength ; i++) {
			var childMapData = new JMap();
			var  tempSeq = this.mapData.get(mapKeys[i]).seq;
			for (var j = i + 1 ; j < mapLength ; j++) {
				if ( tempSeq == this.mapData.get(mapKeys[j]).parentSeq ) {
					childMapData.put(this.mapData.get(mapKeys[j]).seq , this.mapData.get(mapKeys[j]).order);
				}	
			}
			if (childMapData.size() != 0) {
				this.mapData.get(mapKeys[i]).child = childMapData;
				temp.push(mapKeys[i]);
			}
		}
		this.initializeTree();
		this.bugClear();
	},
	
	initializeTree : function() {
		var mapKeys = this.mapData.keys();
		var parentSeq = '0';
		if (mapKeys.length > 0)
			parentSeq = this.mapData.get(mapKeys[0]).seq;
		if (this.actionEvents != null)
			this.makeGuide();
		if (this.makeParent(parentSeq))
			this.makeChildTree(parentSeq, this.mapData.get(parentSeq).child);
		else 
			return;
		$('treeArea').innerHTML = this.buffer.join("");
		this.buffer.clear();
	},
	
	bugClear : function() {
		if (this.actionEvents.move.useYn != "Y")
			return;
		var temp = this.mapData.keys();
		for (var i = 1 ; i < temp.length ; i++) {
			if (this.mapData.get(temp[i]).child != null) {
				this.actionEvent(temp[i], 'move', true);
				this.actionEvent(temp[i], 'move', true);
			}
		}
	},
	
	generateJson : function(temp) {
		return {useYn : temp.useYn, image : temp.image, event : temp.event, title : temp.title, limit : -1};
	},
	
	makeGuide : function() {
		this.enableActionEventCount = 0;
		this.buffer[this.buffer.length] = "	<div align='right'>";
		if (this.actionEvents.insert.useYn == "Y") {
			this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.actionEvents.insert.image +"'> " + this.actionEvents.insert.title + "&nbsp;";
			this.enableActionEventCount++;
			if (this.actionEvents.insert.limit == undefined) 
				this.actionEvents.insert = this.generateJson(this.actionEvents.insert);
			if (this.actionEvents.insert.limit == -1)
				this.actionEvents.insert.limit = this.allowLevel
			
		}
		if (this.actionEvents.update.useYn == "Y") { 
			this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.actionEvents.update.image +"'> " + this.actionEvents.update.title + "&nbsp;";
			this.enableActionEventCount++;
			if (this.actionEvents.update.limit == undefined) 
				this.actionEvents.update = this.generateJson(this.actionEvents.update);
			if (this.actionEvents.update.limit == -1)
				this.actionEvents.update.limit = this.allowLevel
		}
		if (this.actionEvents.del.useYn == "Y") {
			this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.actionEvents.del.image +"'> " + this.actionEvents.del.title + "&nbsp;";
			this.enableActionEventCount++;
			if (this.actionEvents.del.limit == undefined) 
				this.actionEvents.del = this.generateJson(this.actionEvents.del);
			if (this.actionEvents.del.limit == -1)
				this.actionEvents.del.limit = this.allowLevel
		}
		if (this.actionEvents.move.useYn == "Y") {
			this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.actionEvents.move.image +"'> " + this.actionEvents.move.title + "&nbsp;";
			this.enableActionEventCount++;
			if (this.actionEvents.move.limit == undefined) 
				this.actionEvents.move = this.generateJson(this.actionEvents.move);
			if (this.actionEvents.move.limit == -1)
				this.actionEvents.move.limit = this.allowLevel
		}
		if (this.actionEvents.move2.useYn == "Y") {
			this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.actionEvents.move2.image +"'> " + this.actionEvents.move2.title + "&nbsp;";
			this.enableActionEventCount++;
			if (this.actionEvents.move2.limit == undefined) 
				this.actionEvents.move2 = this.generateJson(this.actionEvents.move2);
			if (this.actionEvents.move2.limit == -1)
				this.actionEvents.move2.limit = this.allowLevel
		}
		if (this.actionEvents.select.useYn == "Y") {
			this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.actionEvents.select.image +"'> " + this.actionEvents.select.title + "&nbsp;";
			this.enableActionEventCount++;
			if (this.actionEvents.select.limit == undefined) 
				this.actionEvents.select = this.generateJson(this.actionEvents.select);
			if (this.actionEvents.select.limit == -1)
				this.actionEvents.select.limit = this.allowLevel
		}
		if (this.actionEvents.manage.useYn == "Y") {
			this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.actionEvents.manage.image +"'> " + this.actionEvents.manage.title + "&nbsp;";
			this.enableActionEventCount++;
			if (this.actionEvents.manage.limit == undefined) 
				this.actionEvents.manage = this.generateJson(this.actionEvents.manage);
			if (this.actionEvents.manage.limit == -1)
				this.actionEvents.manage.limit = this.allowLevel
		}
		
		if (this.etc != null) {
			for (var i = 0 ; i < this.etc.length ; i++) {
				this.buffer[this.buffer.length] = "	<img src='" + this.imagePath + this.etc[i].image +"'> " + this.etc[i].title + "&nbsp;";
				this.enableActionEventCount++;
				if (this.etc[i].limit == undefined) 
				this.etc[i] = this.generateJson(this.etc[i]);
				if (this.etc[i].limit == -1)
					this.etc[i].limit = this.allowLevel
			}
		}
		
		this.buffer[this.buffer.length] = "	</div>";
		this.enableActionEventCount = this.enableActionEventCount * 9;
	},
	makeDivTree : function(seq, title) {
		var level = parseInt(this.mapData.get(seq).level);
		var titleWidth = 100 - this.enableActionEventCount;
		this.buffer[this.buffer.length] = "	<div id='div" + seq + "'>";
		this.buffer[this.buffer.length] = "		<table id='table" + seq + "' width='100%' border='0' style='table-layout : fixed;'>";	
		this.buffer[this.buffer.length] = "			<tr>";	
		this.buffer[this.buffer.length] = "				<td id='td" + seq + "' width='" + titleWidth + "%' style='text-overflow : ellipsis; overflow : hidden;' onMouseOver='" + this.objectName + ".showTooltip(\"" + title + "\", \"" + seq + "\");' onMouseOut='" + this.objectName + ".hideTooltip();'>";	
		this.buffer[this.buffer.length] = "					<nobr>" + title + "</nobr>";
		this.buffer[this.buffer.length] = "				</td>";	
		this.buffer[this.buffer.length] = "				<td width='" + this.enableActionEventCount + "%' align='right' style='padding-right : 2px;'>";	
		if (this.actionEvents.insert.useYn == "Y" && parseInt(this.actionEvents.insert.limit) >= level)
			this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.actionEvents.insert.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"insert\");' alt='" + this.actionEvents.insert.title + "' />";
		if (this.actionEvents.update.useYn == "Y" && this.actionEvents.update.limit >= level)
			this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.actionEvents.update.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"update\");' alt='" + this.actionEvents.update.title + "' />";
		if (this.actionEvents.del.useYn == "Y" && this.actionEvents.del.limit >= level)
			this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.actionEvents.del.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"delete\");' alt='" + this.actionEvents.del.title + "' />";
		if (this.actionEvents.move.useYn == "Y" && this.actionEvents.move.limit >= level)
			this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.actionEvents.move.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"move\");' alt='" + this.actionEvents.move.title + "' />";
		if (this.actionEvents.move2.useYn == "Y" && this.actionEvents.move2.limit >= level)
			this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.actionEvents.move2.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"move2\");' alt='" + this.actionEvents.move2.title + "' />";
		if (this.actionEvents.select.useYn == "Y" && this.actionEvents.select.limit >= level)
			this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.actionEvents.select.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"select\");' alt='" + this.actionEvents.select.title + "' />";
		if (this.actionEvents.manage.useYn == "Y" && this.actionEvents.manage.limit >= level)
			this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.actionEvents.manage.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"manage\");' alt='" + this.actionEvents.manage.title + "' />";
		
		if (this.etc != null) {
			for (var i = 0 ; i < this.etc.length ; i++) {
				if (this.etc[i].useYn == "Y" && this.etc[i].limit >= level)
					this.buffer[this.buffer.length] = "					<img src='" + this.imagePath + this.etc[i].image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"" + seq + "\" , \"etc\", \"" + i + "\");' alt='" + this.etc[i].title + "' />";
			}
		}
		
		this.buffer[this.buffer.length] = "				</td>";	
		this.buffer[this.buffer.length] = "			</tr>";	
		this.buffer[this.buffer.length] = "		</table>";	
		this.buffer[this.buffer.length] = "	</div>";		
	},
	
	makeChildTree : function(parentSeq, child) {
		if (child == null)
			return;
		var mapKeys = child.keys();
		this.buffer[this.buffer.length] = "<ul id='ul" + parentSeq +  "'>";
		
		this.makeChildData( mapKeys);
		
		this.buffer[this.buffer.length] = "</ul>";
	},
	
	makeChildData : function( mapKeys) {
		for (var i = 0 ; i < mapKeys.length ; i++) {
			if (i + 1 < mapKeys.length) 
				this.buffer[this.buffer.length] = "<li id='li" + this.mapData.get(mapKeys[i]).seq + "' seq='" + this.mapData.get(mapKeys[i]).seq + "'>";
			else 
				this.buffer[this.buffer.length] = "<li class='end' id='li" + this.mapData.get(mapKeys[i]).seq + "' seq='" + this.mapData.get(mapKeys[i]).seq + "'>";
			this.makeDivTree(this.mapData.get(mapKeys[i]).seq, this.mapData.get(mapKeys[i]).title);
			if (this.mapData.get(mapKeys[i]).child != null) {
				this.makeChildTree(	this.mapData.get(mapKeys[i]).seq, this.mapData.get(mapKeys[i]).child);
			} else {
				this.buffer[this.buffer.length] = "</li>";
			}
		}
		return this.html;
	},
	
	makeParent : function(parentSeq) {
		if (this.mapData.containsKey(parentSeq)) {
			var tdWidth = "100px";
			if (this.masterActionYn != "Y")
				var tdWidth = "200px";
			this.buffer[this.buffer.length] = "<table id='table0'  width='200px' border='0' class='blueb'>";
			this.buffer[this.buffer.length] = "	<tr>";
			this.buffer[this.buffer.length] = "		<td width='" + tdWidth + "'>";
			this.buffer[this.buffer.length] = "		<nobr>" + this.mapData.get(parentSeq).title + "</nobr>";
			this.buffer[this.buffer.length] = "		</td>";
			if (this.masterActionYn == "Y") {
				this.buffer[this.buffer.length] = "		<td width='" + tdWidth + "' align='right' style='padding-right : 2px;'>";	
				if (this.actionEvents.insert.useYn == "Y")
					this.buffer[this.buffer.length] = "			<img src='" + this.imagePath + this.actionEvents.insert.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"0\" , \"insert\");' />";
				if (this.actionEvents.move.useYn == "Y")
					this.buffer[this.buffer.length] = "			<img src='" + this.imagePath + this.actionEvents.move.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"0\" , \"move\");' />";
				if (this.actionEvents.move2.useYn == "Y")
					this.buffer[this.buffer.length] = "			<img src='" + this.imagePath + this.actionEvents.move2.image +"' style='cursor:pointer;' onClick='" + this.objectName + ".actionEvent(\"0\" , \"move2\");' />";
				this.buffer[this.buffer.length] = "		</td>";
			}
			this.buffer[this.buffer.length] = "	</tr>";
			this.buffer[this.buffer.length] = "</table>";
			return true;
		} else {
			return false;
		}
	},
	
	actionEvent : function(element, action, flag) {
		if (this.action != null && this.action != action) {
			alert(message.getMessageString('message_367'));
			return;
		}
		switch (action) {
			case 'insert' : this.insertData(element);
						  	break;
			case 'update' : this.updateData(element);
						  	break;
			case 'delete' : this.deleteData(element);
						  	break;
			case 'move' : 
							if ((this.actionElement == null || this.actionElement == element) && (this.action == null || this.action == action)) {
								this.moveData(element, flag);
							} else {
								alert(message.getMessageString('message_368'));
							}
						  	break;
			case 'move2' : this.moveDataUnder(element);
							break;
			case 'select' : this.select(element);
							break;
			case 'manage' : this.manage(element);
							break;
			case 'etc' 	  : this.etcFunction(element, flag);
							break;
		}
	},
	
	newGeneratorChildData : function(parentSeq) {
		var temp = null;
		if (this.mapData.get(parentSeq).child.size() == 0) {
			this.mapData.get(parentSeq).child = null;
		} else {
			temp = this.mapData.get(parentSeq).child.keys();
			var newChildMapData = new JMap();
			for (var i = 0 ; i < temp.length ; i++) {
				newChildMapData.put(temp[i], i+1);
				this.mapData.get(temp[i]).order = i+1;
			}	
			this.mapData.get(parentSeq).child = newChildMapData;
		}
		return temp;
	},
	
	insertData : function(element) {
		if (element != 0)
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
		else 
			Element.setStyle($('table' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 

		this.actionEvents.insert.event( this.mapData.get( element));
	},
	
	etcFunction : function(element, flag) {
		if (element != 0)
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
		else 
			Element.setStyle($('table' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 

		this.etc[flag].event(this.mapData.get( element));
	},
	
	insertDataUI : function( entity) {
		this.mapData.put(entity.seq, entity);
		if (this.mapData.get(entity.parentSeq).child != null) {
			this.mapData.get(entity.parentSeq).child.put(entity.seq, entity.order);
	//		this.makeChildData(this.mapData.get(entity.parentSeq).child.keys());
	//		$("ul" + entity.parentSeq).innerHTML = this.html;
		} else {
			var childMapData = new JMap();
			this.mapData.get(entity.parentSeq).child = childMapData;
			this.mapData.get(entity.parentSeq).child.put(entity.seq, entity.order);
	//		this.makeChildTree(entity.parentSeq, this.mapData.get(entity.parentSeq).child);
	//		Element.update($("li" + entity.parentSeq), $("li" + entity.parentSeq).innerHTML + this.html);
		}
		this.initializeTree();
		this.bugClear();
	},
	
	updateData : function(element) {
		Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
		this.actionEvents.update.event(this.mapData.get(element));
	},
	
	updateDataUI : function(entity) {
		$('td' + entity.seq).innerHTML = entity.title;
		this.mapData.get(entity.seq).title = entity.title;
		commonUI.action.highlight($('div'+entity.seq));
	},
	
	deleteData : function(element) {
		Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
		if (!confirm(message.getMessageString('message_009'))) { 
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#ECECEC'}); 
			return;
		}
		var result = this.actionEvents.del.event(this.mapData.get( element));
		if( result == 0) {
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#ECECEC'});
			return; 
		}
		else {
			var parentSeq = this.mapData.get(element).parentSeq;
			this.mapData.get( parentSeq).child.remove(element);
			this.mapData.remove(element);
			var temp = this.newGeneratorChildData(parentSeq);
			this.initializeTree();
			this.bugClear();
		}
	},
	
	cancelData : function(element) {
		if (element != 0)
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#ECECEC'}); 
		else 
			Element.setStyle($('table' + this.mapData.get(element).seq), {background : '#B3D6F3'}); 
	},
	
	moveData : function(element, flag) {
		var entity = this.mapData.get(element);
		var childs = this.mapData.get(element).child;
		if (flag == null || !flag) {
			if (childs == null || childs.size() < 2) {
				alert(message.getMessageString('message_281'));
				return;
			}
		}
		var mapKeys = childs.keys();
		if (this.actionElement != null && this.actionElement == element) {
			if (element != 0)
				Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#ECECEC'}); 
			else 
				Element.setStyle($('table' + this.mapData.get(element).seq), {background : '#B3D6F3'}); 
			Sortable.destroy($('ul' + entity.seq));
			for (var i = 0 ; i < mapKeys.length ; i++) {
				Element.setStyle($('div' + this.mapData.get(mapKeys[i]).seq), {background : '#ECECEC'}); 
			}
			this.clearAction();
			
			if (!changeData)
				return;
			else 
				changeData = false;
				
			var elements = new Array();
    		var liElement = $('ul' + entity.seq).down('li', 0);
    		elements.push(liElement);
    		var isNext = true;
    		while (isNext) {
    			liElement = liElement.next()
    			if (liElement != null) {
    				elements.push(liElement);
    			}
    			else {
    				isNext = false;
    			}
    		}
    		var temp = new JMap();
    		for (var i = 0 ; i < elements.length ; i++) {
	 			var tempEntity = this.mapData.get(elements[i].getAttribute('seq'));
	 			temp.put(tempEntity.seq, tempEntity.order)
	 		}
	 		this.mapData.get(element).child = temp;
	 		
	 		var temp = this.newGeneratorChildData(element);
	 		
	 		var entitys = new Array();
	 		for (var i = 0 ; i < temp.length ; i++) {
				entitys.push(this.mapData.get(temp[i]));
			}
			if (this.actionEvents.move.event(entitys) > 0)
				alert(message.getMessageString('message_102'));
			else 
				alert(message.getMessageString('message_204'));
				
			this.initializeTree();
			this.bugClear();
			return;
		}
		Sortable.create($('ul' + entity.seq) , {ghosting:false,constraint:false,hoverclass:'',
	    	onUpdate:function(){
	    	},
	    	onChange:function(element){
	    		changeData = true;
	    		var elements = new Array();
	    		var liElement = $('ul' + entity.seq).down('li', 0);
	    		elements.push(liElement);
	    		var isNext = true;
	    		while (isNext) {
	    			liElement = liElement.next()
	    			if (liElement != null) {
	    				elements.push(liElement);
	    			}
	    			else {
	    				isNext = false;
	    			}
	    		}
	    		for (var i = 0 ; i < elements.length ; i++) {
	    			if (i+1 < elements.length ) {
	    				$(elements[i]).className = "middle";
	    			}
	    			else 
	    				$(elements[i]).className = "end";
	    		}
	    	}
		});		
		if (element != 0)
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
		else 
			Element.setStyle($('table' + this.mapData.get(element).seq), {background : '#FFD5B1'});
		for (var i = 0 ; i < mapKeys.length ; i++) {
			Element.setStyle($('div' + this.mapData.get(mapKeys[i]).seq), {background : '#CBE2F2'}); 
		}
		this.actionElement = element;
		this.action = 'move';
	},
	
	moveDataUnder : function( element){
		if( this.selectedItem) {			
			if( this.mapData.get( element) != this.selectedItem) {
				preParent = this.selectedItem.parentSeq;
				
				if (element != 0)
					Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#CBE2F2'}); 
				else 
					Element.setStyle($('table' + this.mapData.get(element).seq), {background : '#CBE2F2'}); 

				if( preParent == element) {
					alert("현재 지정되어 있는 상위 노드입니다.");
					this.cancelData( element);
					return;
				}
				if( this.isChild( element, this.selectedItem.seq)) {
					alert("자신의 하위 로드를 선택할 수 없습니다.");
					this.cancelData( element);
					return;
				}
				
				this.selectedItem.parentSeq = element;
				
				if (this.actionEvents.move2.event(this.selectedItem) > 0) {
					alert(message.getMessageString('message_102'));
					
					if( this.mapData.get(element).child == null) {
						this.mapData.get(element).child = new JMap();
					}
					this.mapData.get(element).child.put( this.selectedItem.seq, this.selectedItem);
					this.mapData.get(preParent).child.remove( this.selectedItem.seq);
					
					this.mapData.put(this.selectedItem.seq, this.selectedItem);
				}
				else 
					alert(message.getMessageString('message_204'));
					
				this.initializeTree();
				this.bugClear();
			}
			else {
				this.cancelData( element);
			}
			this.selectedItem = null;
		}
		else {
			if (element != 0) {
				Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
				this.selectedItem = this.mapData.get(element);
			}
			else { 
				alert("최상위 노드는 부모 노드를 필요로 하지 않습니다.");
				return;
			}
		} 
	},
	
	select : function( element){		
		if( !this.selectedData.containsKey( element)){
			if( this.actionEvents.select.limit == 1){
				temp = this.selectedData.keys();
		 		for (var i = 0 ; i < temp.length ; i++) {
					this.cancelData( temp[i]);
				}
				this.selectedData.clear(); 
			}
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
			this.selectedData.put( element, this.mapData.get(element));
		}
		else {
			this.cancelData( element);
			this.selectedData.remove( element);
		}
		
		this.actionEvents.select.event(this.mapData.get(element));
	},
	
	manage : function( element){		
		if( !this.selectedData.containsKey( element)){
			if( this.actionEvents.manage.limit == 1){
				temp = this.selectedData.keys();
		 		for (var i = 0 ; i < temp.length ; i++) {
					this.cancelData( temp[i]);
				}
				this.selectedData.clear(); 
			}
			Element.setStyle($('div' + this.mapData.get(element).seq), {background : '#FFD5B1'}); 
			this.selectedData.put( element, this.mapData.get(element));
		}
		else {
			this.cancelData( element);
			this.selectedData.remove( element);
		}
		
		this.actionEvents.manage.event(this.mapData.get(element));
	},
	
	getSelectedData : function(){
		temp = this.selectedData.keys();
 		var entitys = new Array();
 		for (var i = 0 ; i < temp.length ; i++) {
			entitys.push(this.selectedData.get(temp[i]));
		}
		
		return entitys;
	},
	
	isChild : function( element, parentSeq) {
		if( element == 0) return false;
		
		if( this.mapData.get(parentSeq).child) {
			return $('li'+element).descendantOf( $('ul'+parentSeq));
		}
		else return false;
	},
	
	clearData : function() {
		this.mapData.clear();
		$('treeArea').innerHTML = "";
	},
	
	clearAction : function() {
		this.actionElement = null;
		this.action = null;
	},
	
	showTooltip : function(title, seq){
		var mapKeys = this.mapData.keys();
		var parentSeq = '0';
		if (mapKeys.length > 0)
			parentSeq = this.mapData.get(mapKeys[0]).seq;
		var buffer = new Array();
			buffer[buffer.length] = "<table width='300px' border='0' align='center' cellpadding='1' cellspacing='0' style='font-size:11px'>";
			buffer[buffer.length] = "	<tr height='20px'>";
			buffer[buffer.length] = "		<td width='30%' bgcolor='#CCCCCC' style='padding:1px,0px,1px,5px;text-align:center'>" + this.mapData.get(parentSeq).title + "</td>";
			buffer[buffer.length] = "		<td width='70%' bgcolor='#F0F0F0'style='padding:1px,0px,1px,5px'>"+title+"</td>";
			buffer[buffer.length] = "	</tr>";
			buffer[buffer.length] = "	<tr>";
			buffer[buffer.length] = "		<td height='1px' colspan='2'> </td>";
			buffer[buffer.length] = "	</tr>";
			buffer[buffer.length] = "</table>";
	 	docTips.newTip(seq, 5, 15, 0, '<center>' + buffer.join("") + '</center>');
	},
	hideTooltip : function()
	{
		docTips.hide();
	}
}
